﻿import mx.utils.Delegate;

/**
 * ...
 * @author wangjun
 * 
 * 
 * 
 * 
 * 3个回调函数
 * onStt
 * onPP
 * onOK
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 */

class A2.preLoader.subLoader 
{
	private var mc:MovieClip;
	private var ld:MovieClipLoader;
	public function subLoader(scope:MovieClip, container:MovieClip, obj:Object) {
		if (scope == undefined || scope.constructor != MovieClip) {
			throw new Error ('!!! subLoader 构造器:: 无scope');
		}
		if (container == undefined || container.constructor != MovieClip) {
			throw new Error ('!!! subLoader 构造器:: 无容器');
		}
		this.mc = container;
		this.ld = new MovieClipLoader();
		//
		var lis:Object = new Object();
		lis.onLoadStart = Delegate.create(this, function (mc:MovieClip) {
			Delegate.create(scope,obj.onStt)({it:mc});
		});
		lis.onLoadProgress = Delegate.create(this, function (mc:MovieClip, ld:Number, tt:Number) {
			Delegate.create(scope,obj.onPP)({per:Math.round(ld/tt*100), cur:ld, ttl:tt,it:mc});
		});
		lis.onLoadInit = Delegate.create(this, function (mc:MovieClip) {
			Delegate.create(scope,obj.onOK)({it:mc});
		});
		this.ld.addListener(lis);
	}
	public function load(url):Void {
		trace('subLoader ::load url -> '+url+' ctt -> '+this.mc);
		this.ld.loadClip(url, this.mc);
	}
	
}